using System;
using System.IO;

namespace GenDotNet.Condenser
{

   public class Condense
   {

      public static void Main(string[] args)
      {
         if (args.Length == 0)
         {
            Console.WriteLine("Please specify file to condense");
            return;
         }
         for (int i = 0; i < args.Length; i++)
         {
            string suffix = Path.GetExtension(args[0]);
            Console.WriteLine("Please provide a C# or VB source file");
            StreamReader reader = new StreamReader(args[0]);
            String condensed = SemanticCondense(reader.ReadToEnd(), suffix);
            Console.WriteLine(condensed);
         }
      }

      public static String SemanticCondense(
               String text,
               string language)
      {
         Condenser cond = CondenserFromLanguage(language);
         if (cond != null)
         {
            return cond.Run(text);
         }
         return null;
      }

      private static Condenser CondenserFromLanguage(string language)
      {
         // Add new extensions here. I could have managed this 
         // via reflection and attributes but was lazy about it
         switch (language.ToLower())
         {
            case "vb":
               return new VBCondenser();
            case "cs":
            case "csharp":
               return new CSCondenser();
            default:
               return null;
         }
      }

   }

}